const db = require("../../db")
// 获取问题列表
exports.getQue = (req,res) =>{
    var str = "select * from question where isdelete = 0 order by pubdata desc"
    db.query(str,(err,results)=>{
        if(err) return res.cc(err)
        res.send({
            status:0,
            message:"获取成功",
            data:results
        })
    })
}
// 获取问题详情
exports.getDetailQue = (req,res) =>{
    var id = req.query.id
    var str = "select * from question where isdelete = 0 and id =?"
    db.query(str,id,(err,results)=>{
        if(err) return res.cc(err)
        if(results.length != 1) return res.cc("数据库错误,请稍后重新查看")
        const views = results[0].view + 1


        str = "update question set view = ? where id =?"
        // 每调用一次接口，访问量+1
        db.query(str,[views,id],(err,result)=>{
            if(err) return res.cc(err)
            if(result.affectedRows != 1) return res.cc("访客记录获取失败")
            res.send({
                status:0,
                data:results
            })

        })
    })
}